//imgcar 轮播
$(document).ready(function () {
    var swiper = new Swiper('.imgcar .swiper-container', {
        pagination: '.imgcar .swiper-pagination',
        nextButton: '.imgcar .swiper-button-next',
        prevButton: '.imgcar .swiper-button-prev',
        paginationClickable: true,
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: 4500,
        speed: 1000,
        autoplayDisableOnInteraction: false,
        loop: true,
        effect: 'fade',
        fade: {
            crossFade: true
        }
    });
    $(".imgcar").hover(function () {
        $(this).find(".btn").toggle();
    });
    $(".imgcar .swiper-button-prev").mouseenter(function () {
        $(this).css("background", " url('img/banner_sprite.png') no-repeat -80px -42px")
    }).mouseleave(function () {
        $(this).css("background", " url('img/banner_sprite.png') no-repeat 0 -45px")
    });
    $(".imgcar .swiper-button-next").mouseenter(function () {
        $(this).css("background", " url('img/banner_sprite.png') no-repeat -80px -142px")
    }).mouseleave(function () {
        $(this).css("background", " url('img/banner_sprite.png') no-repeat 0 -145px")
    });
    //list部分
    $(".list-box").each(function () {
        var th = $(this);
        th.mouseenter(function () {
            th.find(".before").fadeOut();
            th.find(".after").fadeIn();
            th.addClass("shadow");
            th.find(".imgwrap img").animate({
                width: "336px",
                height: "192px",
                "marginTop": '-16px',
                "marginLeft": "-28px"
            }, 300);
        }).mouseleave(function () {
            th.find(".before").fadeIn();
            th.find(".after").fadeOut();
            th.removeClass("shadow");
            th.find(".imgwrap img").animate({
                "width": "280px",
                "height": "160px", "marginTop": "0px", "marginLeft": "0px"
            }, 300);
        })
    });
    //图片
    $(".picture").mouseenter(function () {
        $(this).find(".cover").fadeOut();
    }).mouseleave(function () {
        $(this).find(".cover").fadeIn();
    });
    $(".picture-inner li").children("div").each(function () {
        $(this).mouseenter(function () {
            var t = $(this);
            timoutid = setTimeout(function () {
                t.children("div").fadeIn();
            }, 700);
        }).mouseleave(function () {
            clearTimeout(timoutid);
            $(this).children("div").fadeOut();
        })

    });
    //手机慕课
    var mkMobile = $(".mk-mobile");
    var mkDown = $(".mk-down");
    $(".code").mouseenter(function () {
        mkMobile.animate({top: "50px", opacity: "0"}, 300);
        mkDown.animate({top: "0", opacity: "1"}, 300);
    }).mouseleave(function () {
        mkDown.animate({top: "50px", opacity: "0"}, 300);
        mkMobile.animate({top: "0", opacity: "1"}, 300);
    });
    $(".weixin").hover(function () {
        $(".scan").toggle();
    });
    //动画

    var arr = [];

    $('.main').each(function (index) {
        var main = $('.main').eq(index);
        var mainHeight = main.height();
        arr[index] = mainHeight;
        var main1Height = main.offset().top + arr[index] / 2;
        var windowHeight1 = $(window).height();
        if (windowHeight1 > main1Height) {
            switch (index) {
                case 0:
                    main2();
                    break;
                case 1:
                    main2();
                    main3();
                    break;
                case 2:
                    main2();
                    main3();
                    main4();
                    break;
                case 3:
                    main2();
                    main3();
                    main4();
                    main5();
                    break;
                case 4:
                    main2();
                    main3();
                    main4();
                    main5();
                    main6();
                    break;
            }
        }
        $(window).on("scroll", function () {
            var scrollHeight1 = $(document).scrollTop();
            if (scrollHeight1 + windowHeight1 > main1Height) {
                switch (index) {
                    case 0:
                        main2();
                        break;
                    case 1:
                        main3();
                        break;
                    case 2:
                        main4();
                        break;
                    case 3:
                        main5();
                        break;
                    case 4:
                        main6();
                        break;
                }
            }
        });
    });
    function main2() {
        $(".main2inner img:first-child").animate({top: "0", opacity: "1"}, 300, function () {
            $(".main2inner img:nth-child(2)").animate({top: "0", opacity: "1"}, 300, function () {
                $(".main2inner img:last-child").animate({top: "0", opacity: "1"}, 300);
            })
        });
    }

    function main3() {
        $(".main3 .video").animate({bottom: "0", opacity: "1"}, 400, function () {
            $(".main3 .star").animate({opacity: "1"}, 400);
        });
        $(".main3 .text").animate({opacity: "1"}, 400);
    }

    function main4() {
        $(".main4 .text2").animate({opacity: "1"}, 400);
        $(".main4 .computer1").animate({top: "-30px", opacity: 1}, 400, function () {
            $(".main4 .computer2").animate({opacity: "1"});
        });
    }

    function main5() {
        $(".main5 .text3").animate({opacity: "1"}, 400);
        $(".main5 .calendar").animate({top: "-31px", opacity: "1"}, 400, function () {
            $(".main5 .rockets").animate({top: "-46px", opacity: "1"});
            $(".main5 .smoke").animate({top: "-31px", opacity: "1"});
        });
    }

    function main6() {
        $(".main6 .text4").animate({opacity: "1"}, 400);
        $(".main6 .hand").animate({top: "-30px", opacity: "1"}, 400, function () {
            $(".main6 .icon").animate({opacity: "1"});
        });
    }


});

